{include file="common/head"}
<head>
  <title>顾客录入</title>

    <link rel="stylesheet" href="/static/flatpickr/flatpickr.min.css">
    <script src="/static/flatpickr/flatpickr.js"></script>

</head>
<style>
  label{width: 18%;}
  .form-control{display:inline-block;width: 80%;}
</style>
<body style="">
    <div class="container p-3 my-3 " style="max-width: 600px;" >
    <h2>顾客录入</h2>
    <form method="post" action="/index.php/customer/customer_add">


      <div class="mb-3">
        <label for="title" class="form-label">姓名:</label>
        <input type="text" class="form-control" id="name" name="name" value="" placeholder="姓名" />
      </div>
      <div class="mb-3">
        <label for="title" class="form-label">手机号码:</label>
        <input type="text" class="form-control" id="mobile" name="mobile" value="" placeholder="手机号码" />
      </div>
      <div class="mb-3">
        <label for="id_card" class="form-label">身份证号码:</label>
        <input type="text" class="form-control" id="id_card" name="id_card" value="" placeholder="身份证号码" />
      </div>  
      <div class="mb-3">
        <label for="address" class="form-label">现居地址:</label>
        <input type="text" class="form-control" id="address" name="address" value="" placeholder="现居地址" />
      </div>        

      <div class="mb-3">
        <label for="title" class="form-label">性别:</label>
          <input type="radio" class="form-check-input" id="radio1" name="sex" value="1"  checked /> 
          <label class="form-check-label" for="radio1">男</label>
          <input type="radio" class="form-check-input" id="radio2" name="sex" value="2" />
          <label class="form-check-label" for="radio2">女</label>
      </div>
      <div class="mb-3">
        <label for="type" class="form-label">顾客类别:</label>
          <select id="type" name="type" class="form-control">
            {foreach $type as $k=>$v}
            <option value="{$k}" {if $k==2} style="display: none" {/if}>{$v}</option>
            {/foreach}
          </select>

       </div>
      <div class="mb-3">
        <label for="inviter_name" class="form-label">邀请人:</label>
        <div class="input-group">
          <input type="hidden" class="form-control" id="inviter" name="inviter" value="" /></c>
          <input type="text" class="form-control" id="inviter_name" value="" placeholder="姓名或者手机号码" /></c>
          <button type="button" id="find_inviter" class="btn btn-info  bi-search" >查找邀请人</button>
        </div>
      </div>


      <button  type="button" class="btn btn-primary" onclick="doSave()">保存(Save)</button>

    </form>
    </div>

<script type="text/javascript">
    flatpickr("#birth_date", {});
    $(".birth_date").flatpickr({
        enableTime: true,
        dateFormat: "Y-m-d H:i:s",
        allowInput:true,
        defaultDate:'2000-01-01'
    });


    $(function(){
      $("#find_inviter").on('click',function(){
        if(!$("#inviter_name").val()) {
          $("#inviter").val('');
          layer.msg('请输入姓名或者手机设置邀请人,清空内容可以删除邀请人！');return;
        }        
        $.post('/index.php/customer/getOne',{nameOrMobile:$("#inviter_name").val()},function(res){
          if(res.code){
            var data = res.data;
            var inviter = data.id;
            $("#inviter").val(inviter);
            layer.msg(res.msg);
          }else{
            layer.msg(res.msg);
          }

        })
      })

    })

    function doSave(){
      if(!$("#name").val()) {
        layer.msg("无效的名称(Invalid name)!");
        return 0;
      }    
      if(!$("#mobile").val()) {
        layer.msg("无效的电话(Invalid mobile)!");
        return 0;
      }        
      //询问框
      layer.confirm('是否确定保存?', {
        btn: ['YES','CANCEL'] //按钮
      }, function(){
        $('form').submit();
      }, function(){
        layer.msg("Cancel!");
        return 0;
      });
    }

</script>


</body>
</html>
